package com.ca.ui.core.view.list;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.ca.ui.core.R;
import com.ca.ui.core.adapter.HasHeaderPaperAdapter;
import com.ca.ui.core.bean.PaperInfo;

import java.util.List;

public class PaperCardListView extends ConstraintLayout {

    public RecyclerView rv;
    public final HasHeaderPaperAdapter adapter = new HasHeaderPaperAdapter(null, null);

    public PaperCardListView(@NonNull Context context) {
        super(context);
        initView(context);
    }

    public PaperCardListView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public PaperCardListView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {

        View view = LayoutInflater.from(context).inflate(R.layout.paper_list_layout, this);

        rv = view.findViewById(R.id.rv);

        rv.setLayoutManager(new LinearLayoutManager(context));
        rv.setAdapter(adapter);
    }

    public void setList(List<PaperInfo> list) {
        adapter.setList(list);
    }

    /**
     * 追加数据
     * @param list 传入的列表为新的数据列表
     */
    public void appendList(List<PaperInfo> list) {
        //  视图控制器中追加新的数据列表
        adapter.appendList(list);
    }

    public void appendListToTop(List<PaperInfo> list) {
        adapter.appendListToTop(list);
    }
}
